package com.yh.csx.bsf.flow.dao.dal;

import com.yh.csx.bsf.flow.core.db.ConvertUtil;
import com.yh.csx.bsf.flow.core.db.DbConn;
import com.yh.csx.bsf.flow.core.util.ArrayUtil;
import com.yh.csx.bsf.flow.dao.dal.auto.t_user_base_dal;
import com.yh.csx.bsf.flow.dao.model.auto.t_user_model;
import lombok.val;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class t_user_dal extends t_user_base_dal {
    public Integer exsit(DbConn conn, String no) {
        val par = new Object[]{no};
        val stringSql = new StringBuilder();
        stringSql.append("select s.id from t_user s where s.no=?");
        val ds = conn.executeList(stringSql.toString(), par);
        if (ds != null && ds.size() > 0) {
            return ConvertUtil.objToInt(ds.get(0).get("id"));
        }
        return 0;
    }
    public t_user_model getByNo(DbConn conn, String no) {
        val par = new Object[]{no};
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from t_user s where s.no=?");
        val ds = conn.executeList(stringSql.toString(), par);
        if (ds != null && ds.size() > 0) {
            return createModel(ds.get(0));
        }
        return null;
    }

    public List<String> filterNos(DbConn conn, List<String> nos) {
        val rs = new ArrayList<String>();
        val par = new Object[]{};
        val stringSql = new StringBuilder();
        stringSql.append("select s.no from t_user s where s.no in ("+ArrayUtil.sqlIn(nos)+")");
        val ds = conn.executeList(stringSql.toString(), par);
        if (ds != null && ds.size() > 0) {
            for (Map<String, Object> dr : ds) {
                rs.add(ConvertUtil.objToStr(dr.get("no")));
            }
        }
        nos.retainAll(rs);
        return rs;
    }
}
